package com.example.sys.solicitation.service;

import com.example.core.mapping.Mapping;
import com.example.core.service.BaseTreeServiceImpl;
import com.example.core.utils.StringUtils;
import com.example.sys.solicitation.dao.SysSolicitationTemplateDao;
import com.example.sys.solicitation.mapping.SysSolicitationTemplateMapping;
import com.example.sys.solicitation.po.SysSolicitationTemplate;
import com.example.sys.solicitation.vo.SysSolicitationTemplateVo;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Service
public class SysSolicitationTemplateServiceImpl extends BaseTreeServiceImpl<SysSolicitationTemplateDao, SysSolicitationTemplate, SysSolicitationTemplateVo> implements SysSolicitationTemplateService {

    @Override
    public Class<? extends Mapping> getMappingClass() {
        return SysSolicitationTemplateMapping.class;
    }

    /***
     * 删除节点的权限
     * @param id
     * @throws Exception
     */
    @Override
    public void delete(String id) throws Exception {
        List list = findByPId(id);
        if (list.isEmpty()){
            super.delete(id);
        }else {
            throw new Exception("禁止删除带有子节点的节点模板");
        }
    }

    /***
     * 查询根节点
     * @param request
     * @param response
     * @return
     */
    @Override
    public List<SysSolicitationTemplate> findRoot(HttpServletRequest request, HttpServletResponse response) {
        String mainId = request.getParameter("mainId");
        if (StringUtils.isNotEmpty(mainId)) {
            return getBaseMapper().findByMainId(mainId);
        }
        return super.findRoot(request, response);
    }
}
